﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using AddIn.EA.Framework;
using System.Runtime.Serialization;
using System.Xml.Serialization;

namespace AddIn.EA.Architecture.ComponentLogic
{
    [Serializable()]
    public class Property : ISerializable
    {
        #region Property
        [XmlElement("Name")]
        public string Name { get; set; }
        [XmlElement("Type")]
        public string Type { get; set; }
        [XmlElement("Notes")]
        public string Notes { get; set; }
        [XmlElement("ComposeKey")]
        public bool ComposeKey { get; set; }
        [XmlElement("ComposeFilter")]
        public bool ComposeFilter { get; set; }
        [XmlElement("RuleSets")]
        public List<RuleSet> RuleSets { get; set; }
        #endregion

        public virtual void Update(Element parentElement)
        {
            // Cria o atributo 
            AttributeClass attrib = CreateAttribute(parentElement);

            // Cria a propriedade
            CreateAttributeProperty(attrib);
        }
        protected AttributeClass CreateAttribute(Element parentElement)
        {
            // Cria o atributo 
            AttributeClass attrib = parentElement.Attributes.AddNew(ResolveName(this.Name), this.Type);
            attrib.Notes = this.Notes;
            attrib.Scope = ElementScope.Private;
            attrib.Update();
            return attrib;
        }
        protected void CreateAttributeProperty(AttributeClass attrib)
        {
            attrib.CreateProperty();
        }
        protected string ResolveName(string name)
        {
            return string.Format("_{0}{1}", name.Substring(0, 1).ToLower(), name.Substring(1));
        }

        #region ISerializable Members

        public void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
